package org.testfire.translator.watij;

import org.testfire.model.FinderType;
import org.testfire.model.TestsetType;
import org.testfire.translator.TestFireTranslator;

/**
 * Created by IntelliJ IDEA.
 * User: granum
 * Date: Sep 2, 2007
 * Time: 3:52:34 PM
 *
 */
public class FinderToWatijTranslator<T> implements TestFireTranslator<FinderType>
{

    /**
     * Will return a syntactically correct Java class, ready to be written out to a java file with the name
     * testset.getName() + ".java" and compiled.
     * @return The source code for a valid java class, containing all test cases.
     */
    public Object translate( TestsetType testset, FinderType finder )
    {
        StringBuilder buf = new StringBuilder();
        buf.append( String.format( "%1$s(", finder.getName() ) );
        for ( String key : finder.getParams().keySet() )
        {
            buf.append( finder.getParams().get( key ).toArgumentString() ).append( ", " );
        }
        if ( finder.getParams().size() > 0 )
        {
            buf.delete( buf.length() - 2, buf.length() );
        }
        buf.append( ")" );
        return buf.toString();
    }
}